#Makefile

include ../config.mak
include sub.mak

all: libi264e.a i264e libhwicodec.a

#libhwicodec.a
HWICODEC_DIR = ../hwicodec
ICOMMON_DIR = ../icommon

# libi264e.a
INCLUDES = ${INCLUDE_COMMON} -Iinclude
INCLUDES += -I$(HWICODEC_DIR)/include
INCLUDES += -I$(ICOMMON_DIR)/include

LDFLAGS = -pthread -lm
CFLAGS = ${CFLAGS_COMMON} $(INCLUDES)

OBJS = $(OBJS-$(I264E))
VPURCOJB += ../../../../../external/$(GCC_VERSION_DIR)/vpu/obj/glibc/jzm_enc_api_nofpic_t21.o

$(OBJS):%.o:%.c
	$(CC) -c $(CFLAGS) -o $@ $<

libi264e.a: $(OBJS) libhwicodec.a $(VPURCOJB)
	$(LD) -EL -o $@ -r -static $(OBJS) $(HWICODEC_DIR)/libhwicodec.a $(VPURCOJB)

libhwicodec.a:
	$(MAKE) -C $(HWICODEC_DIR)

INCLUDECLI = -Iincludecli
LDFLAGCLI = -L. -li264e $(LDFLAGS)
CFLAGCLI = ${CFLAGS_COMMON} $(INCLUDECLI) $(INCLUDES)

OBJCLI = i264e.o srccli/clii264e.o srccli/cliparse.o srccli/input/raw.o srccli/input/v4l2.o srccli/input/thread.o

$(OBJCLI):%.o:%.c
	$(CC) -c $(CFLAGCLI) -o $@ $<

i264e: $(OBJCLI) libi264e.a
	$(CC) -static $(CFLAGCLI) $(LDFLAGCLI) -o $@ $(OBJCLI)

.PHONY: clean distclean
clean:
	$(MAKE) clean -C $(HWICODEC_DIR)
	-rm -f $(OBJS) $(OBJCLI)

distclean: clean
	$(MAKE) distclean -C $(HWICODEC_DIR)
	-rm -f i264e libi264e.a
